package com.stars.easyms.logger;

import com.stars.easyms.logger.asyn.EasyMsAsynLogger;
import com.stars.easyms.logger.config.EasyMsLoggerHelper;
import org.slf4j.Logger;
import org.slf4j.Marker;

/**
 * <p>className: EasyMsLogger</p>
 * <p>description: EasyMs日志打印代理类</p>
 *
 * @author guoguifang
 * @date 2019-08-15 23:45
 * @since 1.3.0
 */
public final class EasyMsLogger implements Logger {

    private static final EasyMsAsynLogger EASY_MS_ASYN_LOGGER = EasyMsAsynLogger.getInstance();

    private Boolean traceEnabled;

    private Boolean debugEnabled;

    private Boolean infoEnabled;

    private Boolean errorEnabled;

    private Boolean warnEnabled;

    private final Logger logger;

    public EasyMsLogger(Logger logger) {
        this.logger = logger;
    }

    @Override
    public void trace(String msg) {
        if (isTraceEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "TRACE", msg, null, null);
            } else {
                logger.trace(msg);
            }
        }
    }

    @Override
    public void trace(String format, Object arg) {
        if (isTraceEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "TRACE", format, new Object[]{arg}, null);
            } else {
                logger.trace(format, arg);
            }
        }
    }

    @Override
    public void trace(String format, Object arg1, Object arg2) {
        if (isTraceEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "TRACE", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.trace(format, arg1, arg2);
            }
        }
    }

    @Override
    public void trace(String format, Object... argArray) {
        if (isTraceEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "TRACE", format, argArray, null);
            } else {
                logger.trace(format, argArray);
            }
        }
    }

    @Override
    public void trace(String msg, Throwable t) {
        if (isTraceEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "TRACE", msg, null, t);
            } else {
                logger.trace(msg, t);
            }
        }
    }

    @Override
    public void trace(Marker marker, String msg) {
        if (logger.isTraceEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "TRACE", msg, null, null);
            } else {
                logger.trace(marker, msg);
            }
        }
    }

    @Override
    public void trace(Marker marker, String format, Object arg) {
        if (logger.isTraceEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "TRACE", format, new Object[]{arg}, null);
            } else {
                logger.trace(marker, format, arg);
            }
        }
    }

    @Override
    public void trace(Marker marker, String format, Object arg1, Object arg2) {
        if (logger.isTraceEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "TRACE", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.trace(marker, format, arg1, arg2);
            }
        }
    }

    @Override
    public void trace(Marker marker, String format, Object... argArray) {
        if (logger.isTraceEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "TRACE", format, argArray, null);
            } else {
                logger.trace(marker, format, argArray);
            }
        }
    }

    @Override
    public void trace(Marker marker, String msg, Throwable t) {
        if (logger.isTraceEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "TRACE", msg, null, t);
            } else {
                logger.trace(marker, msg, t);
            }
        }
    }

    @Override
    public void debug(String msg) {
        if (isDebugEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "DEBUG", msg, null, null);
            } else {
                logger.debug(msg);
            }
        }
    }

    @Override
    public void debug(String format, Object arg) {
        if (isDebugEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "DEBUG", format, new Object[]{arg}, null);
            } else {
                logger.debug(format, arg);
            }
        }
    }

    @Override
    public void debug(String format, Object arg1, Object arg2) {
        if (isDebugEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "DEBUG", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.debug(format, arg1, arg2);
            }
        }
    }

    @Override
    public void debug(String format, Object... argArray) {
        if (isDebugEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "DEBUG", format, argArray, null);
            } else {
                logger.debug(format, argArray);
            }
        }
    }

    @Override
    public void debug(String msg, Throwable t) {
        if (isDebugEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "DEBUG", msg, null, t);
            } else {
                logger.debug(msg, t);
            }
        }
    }

    @Override
    public void debug(Marker marker, String msg) {
        if (logger.isDebugEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "DEBUG", msg, null, null);
            } else {
                logger.debug(marker, msg);
            }
        }
    }

    @Override
    public void debug(Marker marker, String format, Object arg) {
        if (logger.isDebugEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "DEBUG", format, new Object[]{arg}, null);
            } else {
                logger.debug(marker, format, arg);
            }
        }
    }

    @Override
    public void debug(Marker marker, String format, Object arg1, Object arg2) {
        if (logger.isDebugEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "DEBUG", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.debug(marker, format, arg1, arg2);
            }
        }
    }

    @Override
    public void debug(Marker marker, String format, Object... argArray) {
        if (logger.isDebugEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "DEBUG", format, argArray, null);
            } else {
                logger.debug(marker, format, argArray);
            }
        }
    }

    @Override
    public void debug(Marker marker, String msg, Throwable t) {
        if (logger.isDebugEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "DEBUG", msg, null, t);
            } else {
                logger.debug(marker, msg, t);
            }
        }
    }

    @Override
    public void error(String msg) {
        if (isErrorEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "ERROR", msg, null, null);
            } else {
                logger.error(msg);
            }
        }

    }

    @Override
    public void error(String format, Object arg) {
        if (isErrorEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "ERROR", format, new Object[]{arg}, null);
            } else {
                logger.error(format, arg);
            }
        }

    }

    @Override
    public void error(String format, Object arg1, Object arg2) {
        if (isErrorEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "ERROR", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.error(format, arg1, arg2);
            }
        }
    }

    @Override
    public void error(String format, Object... argArray) {
        if (isErrorEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "ERROR", format, argArray, null);
            } else {
                logger.error(format, argArray);
            }
        }
    }

    @Override
    public void error(String msg, Throwable t) {
        if (isErrorEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "ERROR", msg, null, t);
            } else {
                logger.error(msg, t);
            }
        }
    }

    @Override
    public void error(Marker marker, String msg) {
        if (logger.isErrorEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "ERROR", msg, null, null);
            } else {
                logger.error(marker, msg);
            }
        }
    }

    @Override
    public void error(Marker marker, String format, Object arg) {
        if (logger.isErrorEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "ERROR", format, new Object[]{arg}, null);
            } else {
                logger.error(marker, format, arg);
            }
        }
    }

    @Override
    public void error(Marker marker, String format, Object arg1, Object arg2) {
        if (logger.isErrorEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "ERROR", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.error(marker, format, arg1, arg2);
            }
        }
    }

    @Override
    public void error(Marker marker, String format, Object... argArray) {
        if (logger.isErrorEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "ERROR", format, argArray, null);
            } else {
                logger.error(marker, format, argArray);
            }
        }
    }

    @Override
    public void error(Marker marker, String msg, Throwable t) {
        if (logger.isErrorEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "ERROR", msg, null, t);
            } else {
                logger.error(marker, msg, t);
            }
        }
    }

    @Override
    public void info(String msg) {
        if (isInfoEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "INFO", msg, null, null);
            } else {
                logger.info(msg);
            }
        }
    }

    @Override
    public void info(String format, Object arg) {
        if (isInfoEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "INFO", format, new Object[]{arg}, null);
            } else {
                logger.info(format, arg);
            }
        }
    }

    @Override
    public void info(String format, Object arg1, Object arg2) {
        if (isInfoEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "INFO", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.info(format, arg1, arg2);
            }
        }
    }

    @Override
    public void info(String format, Object... argArray) {
        if (isInfoEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "INFO", format, argArray, null);
            } else {
                logger.info(format, argArray);
            }
        }
    }

    @Override
    public void info(String msg, Throwable t) {
        if (isInfoEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "INFO", msg, null, t);
            } else {
                logger.info(msg, t);
            }
        }
    }

    @Override
    public void info(Marker marker, String msg) {
        if (logger.isInfoEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "INFO", msg, null, null);
            } else {
                logger.info(marker, msg);
            }
        }
    }

    @Override
    public void info(Marker marker, String format, Object arg) {
        if (logger.isInfoEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "INFO", format, new Object[]{arg}, null);
            } else {
                logger.info(marker, format, arg);
            }
        }
    }

    @Override
    public void info(Marker marker, String format, Object arg1, Object arg2) {
        if (logger.isInfoEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "INFO", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.info(marker, format, arg1, arg2);
            }
        }
    }

    @Override
    public void info(Marker marker, String format, Object... argArray) {
        if (logger.isInfoEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "INFO", format, argArray, null);
            } else {
                logger.info(marker, format, argArray);
            }
        }
    }

    @Override
    public void info(Marker marker, String msg, Throwable t) {
        if (logger.isInfoEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "INFO", msg, null, t);
            } else {
                logger.info(marker, msg, t);
            }
        }
    }

    @Override
    public void warn(String msg) {
        if (isWarnEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "WARN", msg, null, null);
            } else {
                logger.warn(msg);
            }
        }
    }

    @Override
    public void warn(String msg, Throwable t) {
        if (isWarnEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "WARN", msg, null, t);
            } else {
                logger.warn(msg, t);
            }
        }
    }

    @Override
    public void warn(String format, Object arg) {
        if (isWarnEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "WARN", format, new Object[]{arg}, null);
            } else {
                logger.warn(format, arg);
            }
        }
    }

    @Override
    public void warn(String format, Object arg1, Object arg2) {
        if (isWarnEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "WARN", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.warn(format, arg1, arg2);
            }
        }
    }

    @Override
    public void warn(String format, Object... argArray) {
        if (isWarnEnabled()) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, null, "WARN", format, argArray, null);
            } else {
                logger.warn(format, argArray);
            }
        }
    }

    @Override
    public void warn(Marker marker, String msg) {
        if (logger.isWarnEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "WARN", msg, null, null);
            } else {
                logger.warn(marker, msg);
            }
        }
    }

    @Override
    public void warn(Marker marker, String format, Object arg) {
        if (logger.isWarnEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "WARN", format, new Object[]{arg}, null);
            } else {
                logger.warn(marker, format, arg);
            }
        }
    }

    @Override
    public void warn(Marker marker, String format, Object... argArray) {
        if (logger.isWarnEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "WARN", format, argArray, null);
            } else {
                logger.warn(marker, format, argArray);
            }
        }
    }

    @Override
    public void warn(Marker marker, String format, Object arg1, Object arg2) {
        if (logger.isWarnEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "WARN", format, new Object[]{arg1, arg2}, null);
            } else {
                logger.warn(marker, format, arg1, arg2);
            }
        }
    }

    @Override
    public void warn(Marker marker, String msg, Throwable t) {
        if (logger.isWarnEnabled(marker)) {
            if (EasyMsLoggerHelper.isLogAsynEnabled()) {
                EASY_MS_ASYN_LOGGER.log(logger, marker, "WARN", msg, null, t);
            } else {
                logger.warn(marker, msg, t);
            }
        }
    }

    @Override
    public boolean isTraceEnabled() {
        if (traceEnabled == null) {
            traceEnabled = logger.isTraceEnabled();
        }
        return traceEnabled;
    }

    @Override
    public boolean isTraceEnabled(Marker marker) {
        return logger.isTraceEnabled(marker);
    }

    @Override
    public boolean isDebugEnabled() {
        if (debugEnabled == null) {
            debugEnabled = logger.isDebugEnabled();
        }
        return debugEnabled;
    }

    @Override
    public boolean isDebugEnabled(Marker marker) {
        return logger.isDebugEnabled(marker);
    }

    @Override
    public boolean isInfoEnabled() {
        if (infoEnabled == null) {
            infoEnabled = logger.isInfoEnabled();
        }
        return infoEnabled;
    }

    @Override
    public boolean isInfoEnabled(Marker marker) {
        return logger.isInfoEnabled(marker);
    }

    @Override
    public boolean isErrorEnabled() {
        if (errorEnabled == null) {
            errorEnabled = logger.isErrorEnabled();
        }
        return errorEnabled;
    }

    @Override
    public boolean isErrorEnabled(Marker marker) {
        return logger.isErrorEnabled(marker);
    }

    @Override
    public boolean isWarnEnabled() {
        if (warnEnabled == null) {
            warnEnabled = logger.isWarnEnabled();
        }
        return warnEnabled;
    }

    @Override
    public boolean isWarnEnabled(Marker marker) {
        return logger.isWarnEnabled(marker);
    }

    @Override
    public String getName() {
        return logger.getName();
    }

    @Override
    public String toString() {
        return "EasyMsLogger[" + getName() + "]";
    }

}